package com.dadi.testaidl;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;

import androidx.annotation.Nullable;

/**
 * author: 韦敏敏
 * date: 2019/12/21 0021
 */
public class MAidlService extends Service {
    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.i("liaoming", "onStartCommand");
        return super.onStartCommand(intent, flags, startId);
    }

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        Log.i("liaoming", "onBind");
        return stub;
    }
    IMyAidlInterface.Stub stub = new IMyAidlInterface.Stub() {
        @Override
        public int add(int a, int b) throws RemoteException {
            Log.i("liaoming", "stub-add : " + (a + b));
            return a + b;
        }

        @Override
        public String inPerson(Person person) throws RemoteException {
            String old = "name:" + person.getName() + " age:" + person.getAge();
            Log.i("liaoming", "inPerson : " + old);
            person.setName("李四");
            person.setAge(13);
            return "name: " + person.getName() + " age: " + person.getAge();
        }

        @Override
        public String outPerson(Person person) throws RemoteException {
            String old = "name:" + person.getName() + " age:" + person.getAge();
            Log.i("liaoming", "outPerson : " + old);
            person.setName("周六");
            person.setAge(20);
            return "name: " + person.getName() + " age: " + person.getAge();
        }

        @Override
        public String inOutPerson(Person person) throws RemoteException {
            String old = "name:" + person.getName() + " age:" + person.getAge();
            Log.i("liaoming", "inOutPerson : " + old);
            person.setName("弓七");
            person.setAge(57);
            return "name: " + person.getName() + " age: " + person.getAge();
        }
    };

    @Override
    public boolean onUnbind(Intent intent) {
        Log.i("liaoming", "onUnbind");
        return true;
    }

    @Override
    public void onDestroy() {
        Log.i("liaoming", "onDestroy");
        super.onDestroy();
    }

    @Override
    public void onRebind(Intent intent) {
        Log.i("liaoming", "onRebind()");
        super.onRebind(intent);
    }
}
